<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        html,body{
            width: 100%;
            height: 100%;
        }
        *{
            padding: 0;
            margin: 0;
        }
        .box{
            height: 30px;
            width: 500px;
            background: paleturquoise;
        }
        .box1{
            height: 30px;
            width: 30px;
            background: red;
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="box1"></div>
    </div>
    <script>
        let box=document.querySelector(".box");
        let box1=document.querySelector(".box1");
        let m=box1.style.width;
        let timer;
        t();
        function t(){
            timer=setInterval(function(){
                m++;
                box1.style.width=m+"px";
                if(box1.style.width===500+"px"){
                    clearInterval(timer);
                }
            },100)
        }
        
        box.addEventListener("click",function(event){
            box1.style.width=event.clientX+"px";
            clearInterval(timer);
            setTimeout(function(){
                m=event.clientX;
                t();
            },500)
        })
        
    </script>
</body>
</html>